package com.jp.knowledge.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bm.library.PhotoView;
import com.bumptech.glide.Glide;
import com.jp.knowledge.R;
import com.jp.knowledge.util.ImageLoadUtil;

import java.util.List;

/**
 * Created by jiayen on 17/6/8.
 */

public class PhotoAdapter extends PagerAdapter {

    private Context mContext;
    private List<String> urls;
    public PhotoAdapter(Context mContext,List<String> urls){
        this.mContext=mContext;
        this.urls=urls;
    }
    @Override
    public int getCount() {
        return  urls==null?0:urls.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        PhotoView view = new PhotoView(mContext);
        view.enable();
        view.setScaleType(ImageView.ScaleType.FIT_CENTER);
//        ImageLoadUtil.load(mContext,urls.get(position),view);
        Glide.with(mContext).load(urls.get(position))
//                .error(R.mipmap.morentutouxiang)
//                .placeholder(R.drawable.bg_loading_dialog)
//                .override(width, heigth)
                .into(view);
        container.addView(view);

        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
